<template>
	<view>

		<u-popup :show="show" @close="close" @open="open" mode="center" bgColor="transparent">
			<view class="popup-box">
				<view style="width: 620rpx;height: 800rpx;">
					<view class="popup-top">
						<view class="popup-title">选择合成石</view>
						<view class="close-btn" @click="close()">
							<image src="/static/icon-images/close.png" mode="widthFix"></image>
						</view>
					</view>

					<scroll-view class="scroll" :scroll-y="true">
						<view class="box">
							<view class="card list" v-for="(item,index) in stoneList" :key="index"
								@click="clickStone(item)">
								<view class="logo">
									<image class="logo" :src="uploadUrl+item.materialUrl" mode="widthFix"></image>
								</view>
								<view style="display: flex;align-items: center;justify-content: space-between;">
									<view class="text">
										{{item.materialName}}
									</view>
									<view class="text">
										{{'×'+item.number}}
									</view>
								</view>
							</view>
						</view>
						<view v-if="stoneList.length==0" class="none">暂无合成石</view>
					</scroll-view>
				</view>
			</view>
		</u-popup>


		<u-popup :show="show2" @close="close2" @open="open2" mode="center" bgColor="transparent">
			<view class="popup-box">
				<view style="width: 600rpx;height: auto;">
					<view class="popup-top">
						<view class="popup-title">选择数量</view>
						<view class="close-btn" @click="close2()">
							<image src="/static/icon-images/close.png" mode="widthFix"></image>
						</view>
					</view>
					<view class="air-name" style="margin-top: 20rpx;">请选择您要投入的数量</view>
					<view style="margin-top: 20rpx;">
						<u-slider v-model="value" :step="1" :min="0" :max="maxValue" :showValue="true"></u-slider>
					</view>
					<view class="sure-btns">
						<view class="sure-btn1 card" @click="close2()">取消</view>
						<view class="sure-btn2" @click="submit()">确认</view>
					</view>
				</view>
			</view>
		</u-popup>


	</view>
</template>

<script>
	import {
		getStone
	} from '@/api/plane.js'
	import config from '@/config.js'
	export default {
		props: {
			show: {
				type: Boolean,
				default: false
			},
			checkStone: {
				type: Number,
				default: 0
			},
			checkNumber: {
				type: Number,
				default: 0
			},
		},
		data() {
			return {
				uploadUrl: config.uploadUrl,
				stoneList: [],
				show2: false,
				value: 0,
				maxValue: 50,
				id: 0,
				item: null
			};
		},
		methods: {
			open() {
				this.stoneList = []
				this.$emit('update:show', true);
				this.getList()
			},
			close() {
				this.$emit('update:show', false);
			},
			open2() {
				this.value = 0
				this.maxValue = this.item.number
				this.show2 = true
			},
			close2() {
				this.show2 = false
			},
			clickStone(item) {
				this.item = item
				this.id = item.syntheticId
				this.show2 = true
			},
			async getList() {
				const res = await getStone();
				this.stoneList = res.data
				console.log(this.stoneList);
			},
			submit() {
				if (this.value == 0) {
					uni.showToast({
						icon: 'none',
						title: '合成石数量不可为0'
					})
					return
				}

				this.$emit('update:checkItem', this.item);
				this.$emit('update:checkNumber', this.value);
				this.$emit('update:checkStone', this.id);
				this.$emit('update:show', false);
				this.show2 = false
			}

		}
	}
</script>

<style lang="scss">
	.popup-box {
		background: linear-gradient(135deg, #0a1a3a 0%, #050a1a 100%);
		border: 1rpx solid rgba(255, 255, 255, 0.15);
		border-radius: 20rpx;
		overflow-y: auto;
		padding: 30rpx;
	}

	.popup-top {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.popup-title {
		font-weight: 700;
		font-size: 38rpx;
		color: #e2e8f0;
	}

	.close-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
		background: rgba(255, 255, 255, 0.15);

		image {
			display: block;
			width: 28rpx;
			height: 28rpx;
		}
	}

	.scroll {
		width: 100%;
		height: 720rpx;

		.box {
			padding: 30rpx;
			display: flex;
			flex-wrap: wrap;
			gap: 20rpx;
		}

		.list {
			padding: 20rpx;
		}

		.logo {
			border-radius: 15rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 220rpx;
			height: 220rpx;
		}

		.text {
			margin-top: 20rpx;
			font-size: 28rpx;
			color: #e2e8f0;
			line-height: 1;
			font-weight: 500;
		}

		.none {
			text-align: center;
			margin-top: 20rpx;
			font-size: 28rpx;
			color: #f6f6f6;
			line-height: 1;
			font-weight: 500;
		}
	}

	.popup-box {
		background: linear-gradient(135deg, #0a1a3a 0%, #050a1a 100%);
		border: 1rpx solid rgba(255, 255, 255, 0.15);
		border-radius: 20rpx;
		overflow-y: auto;
		padding: 30rpx;
	}

	.popup-top {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.popup-title {
		font-weight: 700;
		font-size: 38rpx;
		color: #e2e8f0;
	}

	.close-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
		background: rgba(255, 255, 255, 0.15);

		image {
			display: block;
			width: 28rpx;
			height: 28rpx;
		}
	}

	.sure-btns {
		display: flex;
		gap: 30rpx;
		margin-top: 35rpx;

		.sure-btn1 {
			border-radius: 20rpx;
			flex: 1;
			padding: 20rpx 0;
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: #1e293b;
			color: #e2e8f0;
			font-size: 30rpx;
			font-weight: 30rpx;
		}

		.sure-btn2 {
			border-radius: 20rpx;
			flex: 1;
			padding: 20rpx 0;
			display: flex;
			align-items: center;
			justify-content: center;
			background: linear-gradient(135deg, #3b82f6, #3b82f6);
			color: #fff;
			font-size: 30rpx;
			font-weight: 30rpx;
		}
	}

	.air-name {
		line-height: 1;
		font-size: 30rpx;
		font-weight: 600;
		color: #e2e8f0;
	}
</style>